﻿using Common.Communal;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Product.API.Write.Applications.Commands.Material;

namespace Product.API.Write.Controllers
{
    /// <summary>
    /// 物料API-写
    /// </summary>
    [Route("api/[controller]")]
    [ApiController]
    public class MaterialController : ControllerBase
    {
        /// <summary>
        /// 中介者
        /// </summary>
        private readonly IMediator mediator;

        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="mediator">中介者</param>
        public MaterialController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 物料添加
        /// </summary>
        /// <param name="command">请求</param>
        /// <returns>返回任务</returns>
        [HttpPost("CreateMaterial")]
        public async Task<ApiResult<int>> CreateMaterial(CreateMaterialCommand command)
        {
            return await mediator.Send(command);
        }

        /// <summary>
        /// 物料修改
        /// </summary>
        /// <param name="command">请求</param>
        /// <returns>返回任务</returns>
        [HttpPost("UpdateMaterial")]
        public async Task<ApiResult<int>> UpdateMaterial(UpdateMaterialCommand command)
        {
            return await mediator.Send(command);
        }

        /// <summary>
        /// 物料删除
        /// </summary>
        /// <param name="Id">请求</param>
        /// <returns>返回任务</returns>
        [HttpGet("DeleteMaterial")]
        public async Task<ApiResult<int>> DeleteMaterial(int Id)
        {
            DeleteMaterialCommand command = new DeleteMaterialCommand();
            command.Id = Id;
            return await mediator.Send(command);
        }


    }
}
